package components.core
{
	import components.contorls.superClass.BaseToolTip;
	import components.events.DragEvent;
	import components.events.VisibleEvent;
	import components.layout.BaseLayout;
	import components.managers.FocusManager;
	import components.managers.PopUpManager;
	import components.managers.SystemManager;
	import components.managers.ToolTipManager;
	import components.utils.ColorUtil;
	import components.utils.DestroyUtil;
	import components.utils.EventListenerUtil;
	import components.utils.TimeoutIntervalUtil;
	
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;
	import flash.display.Stage;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.filters.ColorMatrixFilter;
	import flash.filters.GlowFilter;
	import flash.geom.Point;
	import flash.utils.clearInterval;
	import flash.utils.clearTimeout;
	import flash.utils.setTimeout;
	
	import mx.binding.utils.ChangeWatcher;
	import mx.core.FlexMovieClip;
	import mx.events.MoveEvent;
	import mx.events.ResizeEvent;
	
    [Event(name = "resize", type = "mx.events.ResizeEvent")]
    [Event(name = "move", type = "mx.events.MoveEvent")]
    [Event(name = "dragEnterEvent", type = "components.events.DragEvent")]
    [Event(name = "dragExitEvent", type = "components.events.DragEvent")]
    [Event(name = "dragDropEvent", type = "components.events.DragEvent")]
	dynamic public class UIComponent extends FlexMovieClip implements IComponent
	{
		private static var listeningForRender:Boolean = false;
		
		public static var methodQueue:Array = [];
		
		protected var invalidateFlag:Boolean;
		
		/**
		 *灰色滤镜
		 */
		public static var grayFilter:ColorMatrixFilter = new ColorMatrixFilter([
			0.3, 0.3, 0.3, 0, 0,
			0.3, 0.3, 0.3, 0, 0,
			0.3, 0.3, 0.3, 0, 0,
			0, 0, 0, 1, 0 ]);
		
		/**
		 *发光滤镜
		 */
		public static var glowFilter:GlowFilter = new GlowFilter();
		
		/**
		 *闪烁间隔时间
		 */
		public static const GLITTER_INTERVAL_TIEM:uint = 1000;
		
		/**
		 * 在所有需要延迟的地方，所有组件都采用统一延迟时间
		 */
		protected var _delayTime:uint = 500;
		
		protected var _height:Number;
		
		protected var _width:Number;
		
		protected var _oldHeight:Number;
		
		protected var _oldWidth:Number;
		
		protected var _oldX:Number;
		
		protected var _oldY:Number;
		
		/**
		 *原始高度、宽度，没有缩放时的 
		 */		
		protected var _normalHeight:Number;
		protected var _normalWidth:Number;
		
		protected var _initialized:Boolean = false;
		
		private var _toolTip:Object;
		
		private var _toolTipClass:Class;
		
		/**
		 *Tip的延迟显示ID
		 */
		private var _toolTipTimeoutID:int;
		
		/**
		 *隐藏Tip的组件检查范围
		 */
		private var _toolTipHideRang:Number = 10;
		
		/**
		 *是否已显示TIP
		 */
		private var _isShowToolTip:Boolean = false;
		
		/**
		 *隐藏TIP时是否设置ToolTipMangager的默认Tip
		 */
		public var destroyCleanToolTip:Boolean = false;
		
		/**
		 *自适应
		 */
		protected var _top:Number = NaN;
		
		protected var _bottom:Number = NaN;
		
		protected var _left:Number = NaN;
		
		protected var _right:Number = NaN;
		
		protected var _horizontalCenter:Number = NaN;
		
		protected var _verticalCenter:Number = NaN;
		
		protected var _parent:DisplayObjectContainer;
		
		public var measureWidth:Number = 0;
		
		public var measureHeight:Number = 0;
		
		/*
		*设置焦点问题
		*/
		protected var _focusComp:UIComponent;
		
		protected var _hasFocus:Boolean;
		
		protected var _focusEnable:Boolean = true;
		
		/**
		 *上次滤镜数据
		 */
		private var _lastFilters:Array = [];
		
		private var _buttonMode:Boolean = false;
		
		/**
		 *动态数据，用于保存临时数据
		 */
		public var dynamicData:Object;
		
		/**
		 *鼠标移动上去时，是否发光
		 */
		protected var _overGlow:Boolean = false;
		
		public var isOver:Boolean = false;
		
		/**
		 *是否创建完成
		 */
		public var isCreateComplete:Boolean = false;
		
        protected var _lastIsCreateComplete:Boolean = false;
		/*
		*拖拽
		*/
		public var dropEnater:Boolean = false;
		/**
		 *拖拽目标组件 
		 */		
		private var _dropTargetComp:UIComponent;
		
		/**
		 *定时闪烁间隔ID
		 */
		private var _glitterIntervalID:uint;
		
        protected var _cwList:Vector.<ChangeWatcher>;

		/**
		 *布局 
		 */		
		protected var _layout:BaseLayout;
		
        protected var _selectedState:Boolean = false;
		
        protected var _backgroundInitHeight:Number = NaN;
		
		
		/**
		 *选中发光滤镜 颜色
		 */		
        private var _selectedFilterColor:Number = 0xFF0000;
		
		/**
		 *自己设置滤镜 
		 */		
        private var _selfSetFilter:Boolean = true;
		
		/**
		 *tf勾边滤镜
		 */
        protected var _tfFilterColor:Number = 0x000000;
		
        protected var _tfFilterEnable:Boolean = false;
		
        public var cleanObjList:Array = [];
		
        public var isDestory:Boolean = false;
		
		/**
		 *是否高亮 
		 */		
        protected var _isBrightness:Boolean = false;
		
        protected var _layoutName:String = "empty";
		
		public function UIComponent()
		{
			_height = height;
			_width = width;
			
            _normalHeight = height / scaleY;
            _normalWidth = width / scaleX;
			
			super();
			
			focusRect = false;
			
            EventListenerUtil.addEventListener(this, Event.FRAME_CONSTRUCTED, frameConstructedHandler);
            EventListenerUtil.addEventListener(this, Event.REMOVED_FROM_STAGE, removedFromStageHandler);
            EventListenerUtil.addEventListener(this, Event.ADDED_TO_STAGE, addedToStageHandler);
            EventListenerUtil.addEventListener(this, MouseEvent.ROLL_OVER, rollOverHandler);
            EventListenerUtil.addEventListener(this, MouseEvent.ROLL_OUT, rollOutHandler);
            EventListenerUtil.addEventListener(this, MouseEvent.CLICK, mouseClickHandler);
            EventListenerUtil.addEventListener(this, MouseEvent.MOUSE_UP, mouseUpHandler);
            EventListenerUtil.addEventListener(this, MouseEvent.MOUSE_DOWN, mouseDownHandler);
			
			scaleX = scaleY = 1;
			
			validate();
			
		}
		
		public function setSize(w:Number, h:Number):void
		{
			_height = h;
			_width = w;
			scaleX = scaleY = 1;
			
			invalidate();
		}
		
		public function get backgroundDisplay():DisplayObject
		{
			if (this.hasOwnProperty("background"))
			{
				return this["background"] as DisplayObject;
			}
			
			return null;
		}
		
		protected function setBackgroundSize(w:Number, h:Number):void
		{
			if (backgroundDisplay)
			{
				backgroundDisplay.x = backgroundDisplay.y = 0;
				backgroundDisplay.width = w;
				backgroundDisplay.height = h;
				
                if (isNaN(_backgroundInitHeight))
                    _backgroundInitHeight = h;
			}
		}
		
		public function callLater(obj:*, method:Function, args:Array = null):Boolean
		{
			if (!listeningForRender)
			{
				var s:Stage = SystemManager.rootStage;
				
				if (!s)
				{
					method.apply(null, args);
					return false;
				}
				
				s.addEventListener(Event.ENTER_FRAME, callLaterDispatcher);
				s.addEventListener(Event.RENDER, callLaterDispatcher);
				s.invalidate();
				
				listeningForRender = true;
			}
			
			methodQueue.push(new MethodQueueElement(obj, method, args));
			
			return true;
		}
		
		private function callLaterDispatcher(event:Event):void
		{
			var s:Stage = SystemManager.rootStage;
			
			var queue:Array = methodQueue;
			methodQueue = [];
			
			for (var i:int = 0; i < queue.length; i++)
			{
				var mqe:MethodQueueElement = queue[i];
				
				if (mqe.obj is UIComponent && mqe.obj.isDestory)
					continue;
				
				if (mqe.obj is UIComponent && mqe.obj.isCreateComplete == false)
				{
					//未创建完成的对象，不进行验证显示
					methodQueue.push(mqe);
				}
				else
					mqe.method.apply(null, mqe.args);
			}
			if (methodQueue.length == 0)
			{
				s.removeEventListener(Event.RENDER, callLaterDispatcher);
				s.removeEventListener(Event.ENTER_FRAME, callLaterDispatcher);
				listeningForRender = false;
			}
			else
			{
				s.invalidate();
			}
			
		}
		
		public function invalidate():void
		{
			if (invalidateFlag || isDestory || !isCreateComplete)
				return;
			
			if (SystemManager.callLater(this, validate))
				invalidateFlag = true;
		}
		
		public function validate():void
		{
			invalidateFlag = false;
			
			commitProperties();
			
			_initialized = true;
			
			measureSizes();
			
			updateDisplayList();
			
            if (!_lastIsCreateComplete && isCreateComplete)
            {
                //创建完成并验证完成
				setTimeout(function():void
				{
                	dispatchEvent(new Event(Event.COMPLETE));
				},100);
		}
		
			_lastIsCreateComplete=isCreateComplete;
        }
		public function validateNow():void
		{
			validate();
			
			var ui:UIComponent;
			for (var i:int = 0; i < numChildren; i++)
			{
				ui = getChildAt(i) as UIComponent;
				if (ui)
					ui.validateNow();
			}
		}
		
		protected function commitProperties():void
		{
			if (parent)
			{
				/*
				*自适应
				*/
				var ph:Number = parent.height;
				var pw:Number = parent.width;
				
				//top bottom
				if (!isNaN(top) && isNaN(bottom))
				{
					myY = _top;
				}
				else if (isNaN(top) && !isNaN(bottom))
				{
					myY = ph - height - _bottom;
				}
				else if (!isNaN(top) && !isNaN(bottom))
				{
					myY = _top;
				}
				else if (!isNaN(verticalCenter))
				{
					myY = ph / 2 - height / 2 + verticalCenter;
				}
				
				//left right
				if (!isNaN(left) && isNaN(right))
				{
					myX = _left;
				}
				else if (isNaN(left) && !isNaN(right))
				{
					myX = pw - width - _right;
				}
				else if (!isNaN(left) && !isNaN(right))
				{
					myX = _left;
				}
				else if (!isNaN(horizontalCenter))
				{
					myX = pw / 2 - width / 2 + horizontalCenter;
				}
			}
			
			dispatchMoveEvent();
		}
		
		protected function measureSizes():Boolean
		{
			var change:Boolean = false;
			
			if (parent)
			{
				/*
				*自适应
				*/
				var ph:Number = parent.height;
				var pw:Number = parent.width;
				var h:Number;
				var w:Number;
				
				//top bottom
				if (!isNaN(top) && !isNaN(bottom))
				{
					h = ph - _top - _bottom;
					if(_height!=h)
					{
						myHeight=h;
						change=true;
					}
				}
				
				//left right
				if (!isNaN(left) && !isNaN(right))
				{
					w = pw - _left - _right;
					if(_width!=w)
					{
						myWidth=w;
						change=true;
					}
				}
			}
			
			setBackgroundSize(width, height);
			
			if (change || width != _oldWidth || height != _oldHeight)
			{
				change = true;
				updateChildSize(this);
				dispatchResizeEvent();
			}
			return change;
		}
		
		protected function updateDisplayList():void
		{
            if (_layout)
				_layout.validate();
		}
		
		private function dispatchMoveEvent():void
		{
			if (_oldX != x || _oldY != y)
			{
				var event:MoveEvent = new MoveEvent(MoveEvent.MOVE);
				event.oldX = _oldX;
				event.oldY = _oldY;
				
				_oldX = x;
				_oldX = y;
				
				dispatchEvent(event);
			}
		}
		
		private function dispatchResizeEvent():void
		{
			if (width != _oldWidth || height != _oldHeight)
			{
				var event:ResizeEvent = new ResizeEvent(ResizeEvent.RESIZE);
				event.oldHeight = _oldHeight;
				event.oldWidth = _oldWidth;
				
				_oldHeight = height;
				_oldWidth = width;
				
				dispatchEvent(event);
			}
		}
		
		public override function get height():Number
		{
			if (isNaN(_height))
				return super.height;
			
			return _height;
		}
		
		public override function set height(value:Number):void
		{
			if (_height == value)
				return;
			
			_height = value;
			
			invalidate();
		}
		
		public function set myHeight(value:Number):void
		{
			if (_height == value)
				return;
			
			_height = value;
            if (backgroundDisplay)
                backgroundDisplay.height = height;
			
			dispatchResizeEvent();
		}
		
		public override function get width():Number
		{
			if (isNaN(_width))
				return super.width;
			
			return _width;
		}
		
		public override function set width(value:Number):void
		{
			if (_width == value)
				return;
			
			_width = value;
			
			invalidate();
		}
		
		public function set myWidth(value:Number):void
		{
			if (_width == value)
				return;
			
			_width = value;
			
            if (backgroundDisplay)
                backgroundDisplay.width = width;
			
			dispatchResizeEvent();
		}
		
		public override function set x(value:Number):void
		{
			if (x == value)
				return;
			
			super.x = value;
			
			invalidate();
		}

		public function set myX(value:Number):void
		{
			super.x = value;
			
			dispatchMoveEvent();
		}
		
		public override function set y(value:Number):void
		{			
			if (y == value)
				return;
			
			super.y = value;
			
			invalidate();
		}
		
		public function set myY(value:Number):void
		{
			super.y = value;
			
			dispatchMoveEvent();
		}
		
		
        [Inspectable(defaultValue = "true")]
		public override function get enabled():Boolean
		{
			return super.enabled;
		}
		
		public override function set enabled(value:Boolean):void
		{
			if (enabled == value)
				return;
			
			super.enabled = value;
			
			if (enabled)
			{
				filters = _lastFilters;
				mouseEnabled = true;
				mouseChildren = true;
			}
			else
			{
				_lastFilters = filters;
				filters = [ grayFilter ];
				mouseEnabled = false;
				mouseChildren = false;
			}
		}
		
        [Inspectable(defaultValue = "false")]
		public function get overGlow():Boolean
		{
			return _overGlow;
		}
		
		public function set overGlow(value:Boolean):void
		{
			_overGlow = value;
		}
		
        [Inspectable(defaultValue = "#000000", type = "Color")]
		public function get tfFilterColor():Number
		{
			return _tfFilterColor;
		}
		
		public function set tfFilterColor(value:Number):void
		{
            _tfFilterColor = value;
			
			setTFFilter();
		}
		
        [Inspectable(defaultValue = "false")]
		public function get tfFilterEnable():Boolean
		{
			return _tfFilterEnable;
		}
		
		public function set tfFilterEnable(value:Boolean):void
		{
            _tfFilterEnable = value;
			
			setTFFilter();
		}
		
		protected function setTFFilter():void
		{
		}
		
        [Inspectable(defaultValue = "empty", type = "List", enumeration = "empty,HLayout,VLayout,VTileLayout,HTileLayout")]
		public function get layoutName():String
		{
			return _layoutName;
		}
		
		public function set layoutName(value:String):void
		{
			_layoutName = value;
			
            if (_layout)
			{
				_layout.destory();
                _layout = null;
			}
			
            _layout = BaseLayout.getNewLayoutInstance(layoutName);
            if (_layout)
			{
                _layout.container = this;
				invalidate();
			}
		}
		
		zn_internal function addChild(child:DisplayObject):DisplayObject
		{
			return super.addChild(child);
		}
		
		zn_internal function addChildAt(child:DisplayObject, index:int):DisplayObject
		{
			return super.addChildAt(child, index);
		}
		
		zn_internal function removeChild(child:DisplayObject):DisplayObject
		{
			return super.removeChild(child);
		}
		
		zn_internal function removeChildAt(index:int):DisplayObject
		{
			return super.removeChildAt(index);
		}
		
		/***************************************
		 *
		 * 事件
		 *
		 * **************************************/
		
		protected function frameConstructedHandler(event:Event):void
		{
			removeEventListener(Event.FRAME_CONSTRUCTED, frameConstructedHandler);
			isCreateComplete = true;
			focusComp = this;
			dropTargetComp = this;
			
			invalidate();
			
		}
		
		protected function removedFromStageHandler(event:Event):void
		{
			stage.removeEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
			if (_isShowToolTip)
				cleanToolTip();
		}
		
		protected function addedToStageHandler(event:Event):void
		{
			stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
		}
		
		protected function rollOverHandler(event:MouseEvent):void
		{
			isOver = true;
			
			if (overGlow && selfSetFilter)
			{
				ColorUtil.brightness(this);
                _isBrightness = true;
			}
			
			showToolTip();
		}
		
		protected function rollOutHandler(event:MouseEvent):void
		{
			isOver = false;
			
            if (_isShowToolTip)
				cleanToolTip();
			
			setSelectedStateFilter();
		}
		
		protected function mouseMoveHandler(event:Event):void
		{
		}
		
		protected function mouseClickHandler(event:MouseEvent):void
		{
			if (event.target is UIComponent)
				FocusManager.currentFocusComp = (event.target as UIComponent).focusComp;
			else
			{
				var p:DisplayObject = event.target.parent;
				while (p)
				{
					if (p is UIComponent)
					{
						FocusManager.currentFocusComp = (p as UIComponent).focusComp;
						break;
					}
					else
						p = p.parent;
				}
			}
		}
		
		
		protected function mouseDownHandler(event:MouseEvent):void
		{
			
		}
		
		protected function mouseUpHandler(event:MouseEvent):void
		{
			
		}
		
		public function get isShow():Boolean
		{
			return stage == null ? false : true;
		}
		
		/***************************************
		 *
		 * ToolTip
		 *
		 * **************************************/
		
		/**
		 * 要显示的Tip数据
		 */
		public function get toolTip():Object
		{
			return _toolTip;
		}
		
		/**
		 * @private
		 */
		public function set toolTip(value:Object):void
		{
			_toolTip = value;
		}
		
		/**
		 *隐藏TIP
		 * @param isShowing 是否正在显示
		 *
		 */
		protected function cleanToolTip(isShowing:Boolean = true):void
		{
			//隐藏ToolTip
			_isShowToolTip = false;
			
			ToolTipManager.destroyToolTip();
			
			clearTimeout(_toolTipTimeoutID);
			
			if (destroyCleanToolTip && isShowing)
				toolTip = null;
		}
		
		/**
		 * 用于处理Tip数据的组件
		 */
		public function get toolTipClass():Class
		{
			return _toolTipClass;
		}
		
		/**
		 * @private
		 */
		public function set toolTipClass(value:Class):void
		{
			_toolTipClass = value;
		}
		
		/**
		 *显示Tip
		 *
		 */
		public function showToolTip():void
		{
			if (toolTip)
			{
				cleanToolTip(false);
				
                _toolTipTimeoutID = TimeoutIntervalUtil.addSetTimeout(this, toolTipTimeout, _delayTime);
				_isShowToolTip = true;
			}
		}
		
		/**
		 *TIP的延迟时间已过，显示TIP
		 *
		 */
		protected function toolTipTimeout():void
		{
			//显示ToolTip
			var point:Point = new Point(mouseX, mouseY);
			point = localToGlobal(point);
			
			ToolTipManager.createToolTip(toolTip, point,toolTipClass);
		}
		
		/**
		 *从场景移除
		 *
		 */
		public function remove():void
		{
			if (parent && parent.contains(this))
				parent.removeChild(this);
			else 
				PopUpManager.removePopUp(this);
		}
		
		/**
		 *马上销毁对象，从内存中释放
		 *
		 */
		public function destroy():void
		{
			if(isDestory)
				return ;
            isDestory = true;
			
			if (SystemManager.rootStage)
				SystemManager.rootStage.removeEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
			
			if (FocusManager.currentFocusComp == focusComp)
				FocusManager.currentFocusComp = null;
			
            if (!(this is BaseToolTip))
				cleanToolTip(false);
			
			remove();
			
			removeCWList();
			
            _cwList = null;
			filters = null;
			_lastFilters = null;
			_toolTip = null;
			_toolTipClass = null;
			_parent = null;
			_focusComp = null;
			_toolTip = null;
			_toolTipClass = null;
			_parent = null;
			_focusComp = null;
			_lastFilters = null;
			dynamicData = null;
			
            _dropTargetComp = null;
            _layout = null;
			
            while (cleanObjList.length > 0)
				DestroyUtil.destroyChild(cleanObjList.pop());
			
            cleanObjList = null;
			
			DestroyUtil.destroyChild(this);
		}
		
		public function get top():Number
		{
			return _top;
		}
		
		public function set top(value:Number):void
		{
            if (_top == value)
                return;
			
			_top = value;
			invalidate();
		}
		
		public function get bottom():Number
		{
			return _bottom;
		}
		
		public function set bottom(value:Number):void
		{
            if (_bottom == value)
                return;
			
			_bottom = value;
			invalidate();
		}
		
		public function get left():Number
		{
			return _left;
		}
		
		public function set left(value:Number):void
		{
            if (_left == value)
                return;
			
			_left = value;
			invalidate();
		}
		
		public function get right():Number
		{
			return _right;
		}
		
		public function set right(value:Number):void
		{
            if (_right == value)
                return;
			
			_right = value;
			invalidate();
		}
		
		public function get horizontalCenter():Number
		{
			return _horizontalCenter;
		}
		
		public function set horizontalCenter(value:Number):void
		{
            if (_horizontalCenter == value)
                return;
			
			_horizontalCenter = value;
			
			_left = _right = NaN;
			invalidate();
		}
		
		public function get verticalCenter():Number
		{
			return _verticalCenter;
		}
		
		public function set verticalCenter(value:Number):void
		{
            if (_verticalCenter == value)
                return;
			
			_verticalCenter = value;
			
			_top = _bottom = NaN;
			invalidate();
		}
		
		override public function get parent():DisplayObjectContainer
		{
			if (_parent == null)
				return super.parent;
			
			return _parent;
		}
		
		public function set parent(value:DisplayObjectContainer):void
		{
			_parent = value;
		}
		
		public function measureChildSize():void
		{
			measureWidth = 0;
			measureHeight = 0;
			var child:DisplayObject;
			for (var i:int = 0; i < numChildren; i++)
			{
				child = getChildAt(i);
				
				measureWidth = Math.max(measureWidth, child.x + child.width);
				measureHeight = Math.max(measureHeight, child.y + child.height);
			}
		}
		
		/***************************************
		 *
		 * Focus
		 *
		 * **************************************/
		public function get focusComp():UIComponent
		{
			return _focusComp;
		}
		
		public function set focusComp(value:UIComponent):void
		{
			_focusComp = value;
		}
		
		/**
		 *获取焦点
		 *
		 */
		public function focusIn():void
		{
			hasFocus = true;
		}
		
		/**
		 *失去焦点
		 *
		 */
		public function focusOut():void
		{
			hasFocus = false;
		}
		
		public function get hasFocus():Boolean
		{
			return _hasFocus;
		}
		
		public function set hasFocus(value:Boolean):void
		{
			_hasFocus = value;
		}
		
		public function get focusEnable():Boolean
		{
			return _focusEnable;
		}
		
		public function set focusEnable(value:Boolean):void
		{
			_focusEnable = value;
		}
		
		
        [Inspectable(defaultValue = "true")]
		public override function get visible():Boolean
		{
			return super.visible;
		}
		
		public override function set visible(value:Boolean):void
		{
            if (visible == value)
                return;
			
			super.visible = value;
			
			dispatchEvent(new VisibleEvent(VisibleEvent.VISIBLE_CHANGE));
		}
		
		
		/**
		 *父对象大小改变，更新子对象大小或坐标
		 *
		 */
		protected function updateChildSize(container:DisplayObjectContainer):void
		{
			var child:UIComponent;
			for (var i:int = 0; i < container.numChildren; i++)
			{
				child = container.getChildAt(i) as UIComponent;
				if (child)
					child.invalidate();
			}
		}
		
        [Inspectable(defaultValue = "false")]
		public override function get buttonMode():Boolean
		{
			return _buttonMode;
		}
		
		public override function set buttonMode(value:Boolean):void
		{
			_buttonMode = value;
			super.buttonMode = value;
		}
		
		
		/**************************************************
		 *拖拽
		 ************************************************/
		
		/**
		 *拖动对象位于此对象上方时
		 * @param data
		 *
		 */
		public function dragEnter(data:*):void
		{
			dispatchEvent(new DragEvent(DragEvent.DRAG_ENTER_EVENT, data));
		}
		
		/**
		 *拖动对象从此对象移出时
		 * @param data
		 *
		 */
		public function dragExit(data:*):void
		{
			dispatchEvent(new DragEvent(DragEvent.DRAG_EXIT_EVENT, data));
		}
		
		/**
		 *拖动对象在此对象上放开时
		 * @param data
		 *
		 */
		public function dragDrop(data:*):void
		{
			dispatchEvent(new DragEvent(DragEvent.DRAG_DROP_EVENT, data));
		}
		
		/**
		 *开始闪烁
		 *
		 */
		public function startGlitter():void
		{
			stopGlitter();
			
            _glitterIntervalID = TimeoutIntervalUtil.addSetInterval(this, function():void
			{
				if (_isBrightness)
				{
					ColorUtil.brightness(this);
                    _isBrightness = true;
				}
				else
				{
					ColorUtil.restore(this);
                    _isBrightness = false;
				}
				
			}, GLITTER_INTERVAL_TIEM);
		}
		
		/**
		 *停止闪烁
		 *
		 */
		public function stopGlitter():void
		{
			clearInterval(_glitterIntervalID);
			ColorUtil.restore(this);
            _isBrightness = false;
		}
		
		public function get cwList():Vector.<ChangeWatcher>
		{
            if (!_cwList)
                _cwList = new Vector.<ChangeWatcher>();
			
			return _cwList;
		}
		
		public function removeCWList():void
		{
            if (_cwList)
			{
				while (_cwList.length > 0)
				{
					_cwList.pop().unwatch();
				}
				
                _cwList = null;
			}
		}
		
		public function get superWidth():Number
		{
			return super.width;
		}
		
		public function set superWidth(value:Number):void
		{
            super.width = value;
		}
			
		public function get superHeight():Number
		{
			return super.height;
		}
		
		public function set superHeight(value:Number):void
		{
            super.height = value;
		}

		public function get layout():BaseLayout
		{
			return _layout;
		}

		public function set layout(value:BaseLayout):void
		{
			_layout = value;
			invalidate();
		}

		public function get isStageMouseIn():Boolean
		{
			if (mouseX > 0 && mouseX < width &&
				mouseY > 0 && mouseY < height)
				return true;
			return false;
		}

		public function get dropTargetComp():UIComponent
		{
			return _dropTargetComp;
		}

		public function set dropTargetComp(value:UIComponent):void
		{
			_dropTargetComp = value;
		}

		public function invalidateChild():void
		{
			var child:UIComponent;
			for (var i:int = 0; i < numChildren; i++)
			{
				child = getChildAt(i) as UIComponent;
				if (child)
					child.invalidate();
			}
		}

		public function get selectedState():Boolean
		{
			return _selectedState;
		}

		public function set selectedState(value:Boolean):void
		{
			_selectedState = value;
			
			setSelectedStateFilter();
		}
		
		protected function setSelectedStateFilter():void
		{
            if (enabled && selfSetFilter)
			{
                if (selectedState)
                    filters = [ new GlowFilter(selectedFilterColor)];
				else 
                    filters = [];
				ColorUtil.restore(this);
                _isBrightness = false;
			}
		}
		
		/**
		 *选中发光滤镜 颜色 
		 * @return 
		 * 
		 */
        [Inspectable(defaultValue = "#FF0000", type = "Color")]
		public function get selectedFilterColor():Number
		{
			return _selectedFilterColor;
		}

		public function set selectedFilterColor(value:Number):void
		{
			_selectedFilterColor = value;
			
			setSelectedStateFilter();
		}

        [Inspectable(defaultValue = "true")]
		public function get selfSetFilter():Boolean
		{
			return _selfSetFilter;
		}

		public function set selfSetFilter(value:Boolean):void
		{
			_selfSetFilter = value;
            if (selfSetFilter == false)
                filters = [];
		}
	}
}